<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Image;
class AgentController extends PublicController {


	function _initialize() {
		parent::_initialize ();
	}
	//代理商列表
    public function index(){
        $search = I('search');
        if($search){
            $where['user_name|company_name'] = array('like',"%$search%");
            $this->assign("search", $search);
        }

        if(I('p')){
            $p = I('p');
        }else{
             $p = 1;
        }
        $header = C('header')['agentList'];
        $where['type'] = 1;
        $count = M('admin')->where($where)->count();
       


        
        $Page = new \Think\Page($count, 30);
        $Page->setConfig('theme', "%UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show = $Page->show(); // 分页显示输出

        $list = M('admin')->where($where)->field('admin_id,user_name,company_name,phone,email,add_time')->order('admin_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        foreach ($list as $k => $v) {
            $list[$k]['add_time'] = date('Y-m-d',$v['add_time']);
        }

        // var_dump($show);exit;
        $show = str_replace('<div>','',$show);
        $show = str_replace('current','active',$show);
        $show = str_replace('<<<','上一页<',$show);
        $show = str_replace('>>>','>下一页',$show);
        $show = str_replace('</div>','',$show);
        // echo  htmlentities($show,ENT_QUOTES,"UTF-8");exit;
        // $show = preg_replace('//s*/', '', $show);
        if($count <= 10){
            $show = '<a href="" class="active">1</a>';
        }
        $this->assign("page", $show); // 赋值分页输出
        $this->assign("count", $count);
        $this->assign("p", $p);
        $this->assign("header", $header);
        $this->assign("list", $list);
        $this->assign("url", $url);
        $this->assign("navs", 'Agent');
        $this->display();
    }


    //代理商列表
    public function ptindex(){
        $search = I('search');
        if($search){
            $where['u.user_name'] = array('like',"%$search%");
            $this->assign("search", $search);
        }
        if(I('p')){
            $p = I('p');
        }else{
             $p = 1;
        }
        $count = M('daily_report')
                ->alias("d")
                ->join("left join pt_admin as u on u.admin_id=d.admin_id")
                ->join("left join pt_business as b on b.admin_id=d.admin_id")
                ->where($where)
                // ->group('d.log_date,d.admin_id desc')
                ->count();
                // ->select();
        $header = C('header')['agentmanagement'];
        $Page = new \Think\Page($count, 30);
        $Page->setConfig('theme', "%UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show = $Page->show(); // 分页显示输出
        $list = M('daily_report')
                ->alias("d")
                ->join("left join pt_admin as u on u.admin_id=d.admin_id")
                ->join("left join pt_business as b on b.admin_id=d.admin_id")
                ->field('u.user_name,sum(d.sitecount),sum(d.keyworlds) as ks,sum(d.standard) as ds,d.admin_id as lv,u.totalmoney,u.money,b.user_name as bname,d.admin_id')
                ->where($where)
                ->group('d.admin_id desc')
                ->limit($Page->firstRow . ',' . $Page->listRows)
                ->select();
        foreach ($list as $k => $v) {
            $list[$k]['user_name'] = '<a href="/Admin/Agent/customer?admin_id='.$v['admin_id'].'">'.$v['user_name'].'</a>';
            $list[$k]['lv'] = round($v['ds']/$v['ks']*100,2).'％';
            $list[$k]['admin_id'] = '<a href="/Admin/Login/agent?admin_id='.$v['admin_id'].'" target="view_window"><button>登录</button></a>';
            $adminList[] = $v['admin_id'];
        }
        if(!empty($adminList)){
            $awhere['a.admin_id'] = array('not in',$adminList);
        }
        
        $adminList = M('admin')
               ->alias("a")
               ->join("left join pt_business as b on b.admin_id=a.admin_id")
               ->field('a.user_name,10,11,12,13,a.totalmoney,a.money,b.user_name as bname,a.admin_id')
               ->where($awhere)
               ->limit($Page->firstRow . ',' . $Page->listRows)
               ->select();

        foreach ($adminList as $k=> $v) {
            $adminList[$k]['10'] = 0;
            $adminList[$k]['11'] = 0;
            $adminList[$k]['12'] = 0;
            $adminList[$k]['13'] = 0;
            $adminList[$k]['admin_id'] = '<a href="/Admin/Login/agent?admin_id='.$v['admin_id'].'" target="view_window"><button>登录</button></a>';
        }
        // var_dump($adminList);exit;

        $list = array_merge($list,$adminList);
        $show = str_replace('<div>','',$show);
        $show = str_replace('current','active',$show);
        $show = str_replace('<<<','上一页<',$show);
        $show = str_replace('>>>','>下一页',$show);
        $show = str_replace('</div>','',$show);
        // echo  htmlentities($show,ENT_QUOTES,"UTF-8");exit;
        // $show = preg_replace('//s*/', '', $show);
        if($count <= 10){
            $show = '<a href="" class="active">1</a>';
        }
        $this->assign("page", $show); // 赋值分页输出
        $this->assign("count", $count);
        $this->assign("p", $p);
        $this->assign("header", $header);
        $this->assign("list", $list);
        $this->assign("navs", 'Agent');
        layout('Layout/twolayout');
        $this->display();
    }


    public function edit(){
		$admin_id = I('admin_id');
        if(!$admin_id){
            $this->ajaxreturn(array('state' => 0, 'data' => '信息错误'), 'json');
        }
        $where['admin_id'] = $admin_id;
        
        $list = M('admin')->where($where)->field('admin_id,user_name,company_name,phone,email,qq,websites,icp,address')->find();
        if(empty($list)){
            $this->ajaxreturn(array('state' => 0, 'data' => '不存在该用户'), 'json');
        }else{
            $url = 'http://'.$_SERVER['HTTP_HOST'].'/Agent/?admin_id='.$list['admin_id'];
            $this->ajaxreturn(array('state' => 1, 'data' => $list,'url'=>$url), 'json');
        }
    }

    public function alerts(){
		$this->display();
    }

    public function add(){
        $this->display();
    }



    //代理商
    public function handle(){
        $res = I('');
        if($res['act'] == 'add'){
            if(!$_FILES['logo'] || !$_FILES['ico']){
                $this->error('请上传logo与ico');exit;
            }
            if(!$res['user_name'] || !$res['password'] || !$res['websites'] || !$res['company_name'] || !$res['phone'] || !$res['qq'] || !$res['email'] || !$res['icp'] || !$res['address']){
                $this->error('请填写完整信息');
            }
           
            $data = $this->upload();
            $res['logo'] = $data['logo'];
            $res['ico'] = $data['ico'];
            $res['add_time'] = time();
            $res['update_time'] = time();
            $res['type'] = 1;
            $res['password'] = md5($res['password']);
            $res['permissions'] = json_encode($res['permissions']);
            $list = M('admin')->add($res);
            if($list){
                $this->success("添加成功", U("Agent/index"));exit;
            }else{
                $this->error("添加失败");exit;
            }

            $this->display();
        }elseif($res['act'] == 'edit'){
            $data = [];
            // var_dump($_FILES);exit;
            if($_FILES['logo']['name'] || $_FILES['ico']['name']){
                $data = $this->upload();
            }
            if($res['password']){
                $update['password'] = md5($res['password']);
            }

            if($res['permissions']){
                $update['permissions'] = json_encode($res['permissions']);
            }
            $update['user_name'] = $res['user_name'];
            $update['company_name'] = $res['company_name'];
            $update['phone'] = $res['phone'];
            $update['email'] = $res['email'];
            $update['qq'] = $res['qq'];
            $update['websites'] = $res['websites'];
            $update['icp'] = $res['icp'];
            $update['address'] = $res['address'];
            $update['update_time'] = time();
            $update = array_merge($data,$update);
            $where['admin_id'] = $res['admin_id'];
            $list = M('admin')->where($where)->save($update);
            if($list){
                $this->success("更新成功", U("Agent/index"));exit;
            }else{
                $this->error("更新失败");exit;
            }
        }elseif($res['act'] == 'del'){
            $where['admin_id'] = $res['admin_id'];
            $list = M('admin')->where($where)->delete($res);
            if($list){
                $this->success("删除成功", U("Agent/index"));exit;
            }else{
                $this->error("删除失败");exit;
            }
        }
       
        
    }


    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =      ''; // 设置附件上传（子）目录
        // 上传文件 
        $info   =   $upload->upload();

        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
            foreach($info as $file){
                $files[$file['key']] =  '/Uploads/'.$file['savepath'].$file['savename'];
            }
        }

        return $files;
    }


    public function customer(){
        $admin_id = I('admin_id');
        if(empty($admin_id)){
            if (session('admin_id_Agent')){
                $admin_id = session('admin_id_Agent');
            }else{
                $this->error('信息错误');exit;
            }

        }
        session('admin_id_Agent',$admin_id);
        $search = I('search');
        if($search){
            $where['u.user_name'] = array('like',"%$search%");
            $this->assign("search", $search);
        }
        if(I('p')){
            $p = I('p');
        }else{
             $p = 1;
        }
        $where['d.admin_id'] = $admin_id;
        $where['d.log_date'] = date("Y-m-d",time());
        $count = M('daily_report_user')
                ->alias("d")
                ->join("left join pt_user as u on u.user_id=d.user_id")
                ->join("left join pt_business as b on b.user_id=d.user_id")
                ->field('u.user_name,u.add_time,b.user_name as bname,d.sitecount,d.keyworlds,d.standard,u.totalmoney,u.money,u.money,u.money,u.status')
                ->where($where)
                ->count();
        $header = C('header')['userlist'];
        $Page = new \Think\Page($count, 30);
        $Page->setConfig('theme', "%UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show = $Page->show(); // 分页显示输出
        $list = M('daily_report_user')
                ->alias("d")
                ->join("left join pt_user as u on u.user_id=d.user_id")
                ->join("left join pt_business as b on b.user_id=d.user_id")
                ->field('u.user_name,u.add_time,b.user_name as bname,d.sitecount,d.keyworlds,d.standard,u.totalmoney,u.money,u.money as tdyue,u.status,u.user_id')
                ->where($where)
                ->limit($Page->firstRow . ',' . $Page->listRows)
                ->select();
        $status = ['正常','欠费'];
        foreach ($list as $k => $v) {
            $list[$k]['user_name'] = '<a href="/Admin/Agent/user?user_id='.$v['user_id'].'">'.$v['user_name'].'</a>';
            $list[$k]['add_time'] = date("Y-m-d H:i:s",$v['add_time']);
            $list[$k]['status'] = $status[$v['status']];
            $list[$k]['user_id'] = '<a href="#" class="add" user_id='.$v['user_id'].'>日报表</a>';
            $list[$k]['user_ida'] = '<a href="/Admin/Agent/udetailsup?user_id='.$v['user_id'].'" >导出</a>';
        }

        // var_dump($show);exit;
        $show = str_replace('<div>','',$show);
        $show = str_replace('current','active',$show);
        $show = str_replace('<<<','上一页<',$show);
        $show = str_replace('>>>','>下一页',$show);
        $show = str_replace('</div>','',$show);
        // echo  htmlentities($show,ENT_QUOTES,"UTF-8");exit;
        // $show = preg_replace('//s*/', '', $show);
        if($count <= 10){
            $show = '<a href="" class="active">1</a>';
        }
        $this->assign("page", $show); // 赋值分页输出
        $this->assign("count", $count);
        $this->assign("p", $p);
        $this->assign("header", $header);
        $this->assign("list", $list);
        $this->assign("navs", 'Agent');
        layout('Layout/twolayout');
        $this->display();
    }


    public function user(){
        $user_id = I('user_id');
        if(empty($user_id)){
            if (session('user_id_Agent')){
                $user_id = session('user_id_Agent');
            }else{
                $this->error('信息错误');exit;
            }

        }
        session('user_id_Agent',$user_id);
        $search = I('search');
        $status = I('status');
        if($status == "0"){
           $where['w.status'] = 0;
           $this->assign("status", 0);
        }else{
            $where['w.status'] = 1;
        }

        if($status){
            $where['w.status'] = $status;
            $this->assign("status", $status);
        }
        if($search){
            $where['w.keyword|u.user_name'] = array('like',"%$search%");
            $this->assign("search", $search);
        }

        $seo = I('seo');
        if($seo){
            $where['w.seo'] = array('eq',$seo);
            $this->assign("seo", $seo);
        }

        if(I('p')){
            $p = I('p');
        }else{
             $p = 1;
        }
        $where['w.user_id'] = $user_id;
        $count = M('worlddetails')
                ->alias("w")
                ->join("left join pt_user as u on u.user_id=w.user_id")
                ->join("left join pt_business as b on b.user_id=w.user_id")
                ->where($where)
                ->count();
        $header = C('header')['user'];
        $Page = new \Think\Page($count, 30);
        $Page->setConfig('theme', "%UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show = $Page->show(); // 分页显示输出

        $seo = [1=>'百度PC','百度移动','360PC','360移动','搜狗PC','搜狗移动'];
        $statusList = ['待优化','优化中','停止优化'];
        $seo_site = [
            '百度PC' => 'https://www.baidu.com/s?&wd=',
            '百度移动' => 'http://wap.baidu.com/s?word=',
            '360PC' => 'https://www.so.com/s?q=',
            '360移动' => 'https://m.so.com/s?q=',
            '搜狗PC' => 'http://www.sogou.com/sogou?query=',
            '搜狗移动' => 'https://m.sogou.com/web/searchList.jsp?keyword=',
        ];



        if (I('exel')==1){
            if(I('amount')){
                 $list = M('worlddetails')
                ->alias("w")
                ->join("left join pt_user as u on u.user_id=w.user_id")
                ->field('u.user_name,w.seo,w.keyword,w.site,w.amount,w.price,u.update_time,w.rank,w.last_rank,w.price as charge,w.standard,w.logtime,w.status')
                ->where($where)
                ->select();
            }else{
                $list = M('worlddetails')
                ->alias("w")
                ->join("left join pt_user as u on u.user_id=w.user_id")
                ->field('u.user_name,w.seo,w.keyword,w.site,w.price,u.update_time,w.rank,w.last_rank,w.price as charge,w.standard,w.logtime,w.status')
                ->where($where)
                ->select();
            }
           
            // $status = ['优化中','欠费'];
            // var_dump($list);exit;
            foreach ($list as $k => $v) {
                $list[$k]['seo'] =  $seo[$v['seo']];
                $list[$k]['keyword'] =  $v['keyword'];
                $list[$k]['site'] =  $v['site'];
                $list[$k]['update_time'] = date("Y-m-d H:i:s",$v['update_time']);
                $list[$k]['logtime'] = date("Y-m-d H:i:s",$v['logtime']);
                $list[$k]['status'] = $statusList[$v['status']];
            }
        }else if($status == "0"){
            // echo 555;exit;
            $header = array("客户", "分组", "关键词", "网址","实价", "价格",'添加时间','更新时间','状态','详情');
             $list = M('worlddetails')
                ->alias("w")
                ->join("left join pt_user as u on u.user_id=w.user_id")
                ->field('u.user_name,w.seo,w.keyword,w.site,w.amount,w.price,u.update_time,w.status,w.id as detail')
                ->where($where)
                ->limit($Page->firstRow . ',' . $Page->listRows)
                ->select();
            // $status = ['优化中','欠费'];
            // var_dump($list);exit;
            foreach ($list as $k => $v) {
                $list[$k]['seo'] =  $seo[$v['seo']];
                $list[$k]['keyword'] =  '<a href="'.$seo_site[$seo[$v['seo']]].$v['keyword'].'" target="_blank">'.$v['keyword'].'</a>';
                $list[$k]['site'] =  '<a href="http://'.$v['site'].'" target="_blank">'.$v['site'].'</a>';
                $list[$k]['update_time'] = date("Y-m-d H:i:s",$v['update_time']);
                $list[$k]['logtime'] = date("Y-m-d H:i:s",$v['logtime']);
                $list[$k]['status'] = $statusList[$v['status']];
                $list[$k]['detail'] = '<a href="#" class="detail" wid='.$v['detail'].'>详情</a>';
            
            }
        }else{
            $list = M('worlddetails')
                ->alias("w")
                ->join("left join pt_user as u on u.user_id=w.user_id")
                ->field('w.id,u.user_name,w.seo,w.keyword,w.site,w.amount,w.price,u.update_time,w.rank,w.last_rank,w.price as charge,w.standard,w.logtime,w.status,w.user_id,w.id as detail')
                ->where($where)
                ->limit($Page->firstRow . ',' . $Page->listRows)
                ->select();
            // $status = ['优化中','欠费'];
            // var_dump($list);exit;
            foreach ($list as $k => $v) {
                $list[$k]['seo'] =  $seo[$v['seo']];
                $list[$k]['keyword'] =  '<a href="'.$seo_site[$seo[$v['seo']]].$v['keyword'].'" target="_blank">'.$v['keyword'].'</a>';
                $list[$k]['site'] =  '<a href="http://'.$v['site'].'" target="_blank">'.$v['site'].'</a>';
                $list[$k]['update_time'] = date("Y-m-d H:i:s",$v['update_time']);
                $list[$k]['logtime'] = date("Y-m-d H:i:s",$v['logtime']);
                $list[$k]['status'] = $statusList[$v['status']];
                $list[$k]['user_id'] = '<a href="#" class="add" user_id='.$v['user_id'].' seo='.$v['seo'].' keyword='.$v['keyword'].'>日报表</a>';
                $list[$k]['user_ida'] = '<a href="/Admin/Agent/userup?user_id='.$v['user_id'].'" >导出</a>';
                $list[$k]['detail'] = '<a href="#" class="detail" wid='.$v['detail'].'>详情</a>';
                if($v['last_rank'] > 10){
                     $list[$k]['charge'] = 0;
                }else{
                    $list[$k]['last_rank'] = '<span style="color:red">'.$v['last_rank'].'</span>';
                }
            }
        }

        if ($list && I('exel')==1){
            $filename = "数据-";
            if(I('amount')){
                $headArr = array("客户", "分组", "关键词", "网址","实价", "价格",'添加时间','初排','新排','今日消费','达标天数','更新时间','状态');
            }else{
                $headArr = array("客户", "分组", "关键词", "网址", "价格",'添加时间','初排','新排','今日消费','达标天数','更新时间','状态');
            }
            
            getExcel($filename, $headArr, $list);
        }

        $show = str_replace('<div>','',$show);
        $show = str_replace('current','active',$show);
        $show = str_replace('<<<','上一页<',$show);
        $show = str_replace('>>>','>下一页',$show);
        $show = str_replace('</div>','',$show);
        // echo  htmlentities($show,ENT_QUOTES,"UTF-8");exit;
        // $show = preg_replace('//s*/', '', $show);
        if($count <= 10){
            $show = '<a href="" class="active">1</a>';
        }
        $this->assign("page", $show); // 赋值分页输出
        $this->assign("count", $count);
        $this->assign("p", $p);
        $this->assign("header", $header);
        $this->assign("list", $list);
        $this->assign("navs", 'Agent');
        $this->assign("user_id", $user_id);
        layout('Layout/twolayout');
        $this->display();
    }




    public function details(){
        $user_id = I('user_id');
        $seo = I('seo');
        $keyword = I('keyword');
        if(empty($user_id) || empty($seo) || empty($keyword)){
            $this->ajaxreturn(array('state' => 2, 'data' => '信息错误'), 'json');
        }

        $where['w.user_id'] = $user_id;
        $where['w.uid'] = array('eq',$user_id);
        $where['w.seo'] = array('eq',$seo);
        $where['w.type'] = array('eq',2);
        $where['w.keyword_id'] = array('eq',$keyword);
        $list = M('worlddetails')
                ->alias("w")
                ->join("left join pt_user as u on u.user_id=w.user_id")
                ->field('u.user_id,u.user_name,w.keyword,w.logtime,w.standard,w.price,u.status')
                ->where($where)
                ->select();
        if($list){
            $n = 1;
            foreach ($list as $k => $v) {
                $list[$k]['user_id'] = $n;
                $list[$k]['standard'] = '排名消费';
                $list[$k]['logtime'] = date("Y-m-d H:i:s",$v['logtime']);
                $list[$k]['status'] = date("Y-m-d H:i:s",$v['logtime']).'任务达标扣费';
                $n++;
            }
            $this->ajaxreturn(array('state' => 1, 'data' => $list), 'json');
        }else{
            $this->ajaxreturn(array('state' => 1, 'data' => '数据为空'), 'json');
        }
    }

    public function udetails(){
        $user_id = I('user_id');
        if(!$user_id){
            $this->ajaxreturn(array('state' => 2, 'data' => '信息错误'), 'json');
        }

        $where['d.user_id'] = $user_id;
        $list = M('daily_report_user')
                ->alias("d")
                ->join("left join pt_user as u on u.user_id=d.user_id")
                ->field('u.user_id,u.user_name,d.log_date,d.sitecount,d.standard,d.pay_amount,u.status')
                ->group('d.log_date')
                ->where($where)
                ->select();
        if($list){
            $n = 1;
            foreach ($list as $k => $v) {
                $list[$k]['user_id'] = $n;
                $list[$k]['sitecount'] = '排名消费';
                $list[$k]['status'] = $v['log_date'].'任务达标扣费';
                $n++;
            }
            $this->ajaxreturn(array('state' => 1, 'data' => $list), 'json');
        }else{
            $this->ajaxreturn(array('state' => 1, 'data' => '数据为空'), 'json');
        }
        

    }

    public function udetailsup(){
        $user_id = I('user_id');
        if(!$user_id){
            $this->error('信息错误');exit;
        }

        $where['d.user_id'] = $user_id;
        $list = M('daily_report_user')
            ->alias("d")
            ->join("left join pt_user as u on u.user_id=d.user_id")
            ->field('u.user_id,u.user_name,d.log_date,d.sitecount,d.standard,d.pay_amount,u.status')
            ->group('d.log_date')
            ->where($where)
            ->select();
        if($list){
            $n = 1;
            foreach ($list as $k => $v) {
                $list[$k]['user_id'] = $n;
                $list[$k]['sitecount'] = '排名消费';
                $list[$k]['status'] = $v['log_date'].'任务达标扣费';
                $n++;
            }
            $this->udetailsupexport($list);
        }else{
            $this->error('暂无数据');exit;
        }


    }

    public function userup(){
        $user_id = I('user_id');
        if(!$user_id){
            $this->error('信息错误');exit;
        }

        $where['w.user_id'] = $user_id;
        $list = M('worlddetails')
            ->alias("w")
            ->join("left join pt_user as u on u.user_id=w.user_id")
            ->field('u.user_id,u.user_name,w.keyword,w.logtime,w.standard,w.price,u.status')
            ->where($where)
            ->select();
        if($list){
            $n = 1;
            foreach ($list as $k => $v) {
                $list[$k]['user_id'] = $n;
                $list[$k]['standard'] = '排名消费';
                $list[$k]['logtime'] = date("Y-m-d H:i:s",$v['logtime']);
                $list[$k]['status'] = date("Y-m-d H:i:s",$v['logtime']).'任务达标扣费';
                $n++;
            }
            $this->userexport($list);
        }else{
            $this->error('暂无数据');exit;
        }

    }

    /**
     * 导出
     */
    public function userexport($arr)
    {
        if (!$arr){
            return false;
        }
        $filename = "日报表";
        $headArr = array("ID", "客户", "关键字", "交易时间", "交易类别", "资金变动",'备注');
        getExcel($filename, $headArr, $arr);
    }

    /**
     * 导出
     */
    public function udetailsupexport($arr)
    {
        if (!$arr){
            return false;
        }
        $filename = "日报表";
        $headArr = array("ID", "客户", "交易时间", "交易类别", "达标词数", "资金变动",'备注');
        getExcel($filename, $headArr, $arr);
    }


    public function ftp(){
        $wid = I('wid');
        if(empty($wid)){
            $this->ajaxreturn(array('state' => 2, 'data' => '信息错误'), 'json');
        }
        $where['w.id'] = $wid;
        $list = M('worlddetails')
                ->alias("w")
                ->join("left join pt_site as s on w.user_id=s.user_id")
                ->field('w.*,s.ftp_ip')
                ->where($where)
                ->find();
        if($list){
            $seo = [1=>'百度PC','百移移动','360PC','360移动','搜狗PC','搜狗移动'];
            $list['seo'] = $seo[$list['seo']];
            $this->ajaxreturn(array('state' => 1, 'data' => $list), 'json');
        }else{
            $this->ajaxreturn(array('state' => -1, 'data' => '数据为空'), 'json');
        }
                
    }



    public function stop(){
        $widList = I('wid');
        if(empty($widList)){
            $this->ajaxreturn(array('state' => 2, 'data' => '信息错误'), 'json');
        }

        $where['id'] = array('in',$widList);
        $update['status'] = 2;
        $list = M('worlddetails')->where($where)->save($update);
        if($list){
            $this->ajaxreturn(array('state' => 1, 'data' => '停止成功'), 'json');
        }else{
            $this->ajaxreturn(array('state' => -1, 'data' => '数据为空'), 'json');
        }            
    }


}